package com.yqya.springboot.mybatisplus.shardingjdbc.shardingjdbc;

import java.util.Collection;

import io.shardingsphere.core.api.algorithm.sharding.PreciseShardingValue;
import io.shardingsphere.core.api.algorithm.sharding.standard.PreciseShardingAlgorithm;


/**
 * 分库策略
 *
 * @author Kevin
 * @date 2019-08-03
 */
public class MemberIdShardingSchemeAlgorithm implements PreciseShardingAlgorithm<Long> {

    @Override
    public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Long> shardingValue) {
        for (String str : availableTargetNames) {
            long index = shardingValue.getValue() % 100;
            return str + (index > 49 ? "2" : "1");
        }
        return null;
    }

}
